#include <bits/stdc++.h>
// 2025/01/24
// tag: 
// Author: Zhang Muen
using namespace std;

int n, m, EnteringDegree[5001], OutDegree[5001], ans[5001];
vector<int> g[5001];

signed main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u, v;
        cin >> v >> u;
        g[u].push_back(v);
        EnteringDegree[v]++;
        OutDegree[u]++;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++)
        if (EnteringDegree[i] == 0)
            q.push(i), ans[i] = 1;
    while (!q.empty()){
        int u = q.front();
        q.pop();
        for (int i = 0; i < g[u].size(); i++){
            int v = g[u][i];
            EnteringDegree[v]--;
            ans[v] = (ans[v] + ans[u]) % 80112002;
            if (EnteringDegree[v] == 0)
                q.push(v);
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        if (OutDegree[i] == 0)
            cnt = (cnt + ans[i]) % 80112002;
    cout << cnt;
    return 0;
}